:root {
    --primary-color: #2563eb;
    --secondary-color: #1e40af;

    /* 新增主题变量 */
    :root {
        --bg-color: #ffffff;
        --text-color: #1e293b;
        --primary-bg: #f8fafc;
        --nav-bg: #2563eb;
        --border-color: #e2e8f0;
    }

    body.dark {
        --bg-color: #1a1a1a;
        --text-color: #e5e7eb;
        --primary-bg: #2d2d2d;
        --nav-bg: #1e40af;
        --border-color: #3a3a3a;
    }

    /* 修复消息气泡背景色 */
    .user-message {
        background: var(--primary-color);
    }

    .assistant-message {
        background: var(--primary-bg);
    }

    /* 修复聊天框背景 */
    #chatbox {
        background: var(--primary-bg);
    }

    background: white;
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    /* height: 10vh; */
    margin: 1rem 0;
    /* padding: 1.5rem; */
    overflow-y: auto;
}

.message {
    margin: 0.8rem 0;
    padding: 1rem 1.5rem;
    border-radius: 15px;
    max-width: 92%;
    /* 从85%调整为92% */
    min-width: 80px;
    /* 从120px减少到80px */
    width: fit-content;
    /* 新增自适应宽度 */
}



.assistant-message {
    margin-right: auto;
    max-width: 90%;
    /* 助理消息稍宽便于长文本阅读 */
}

.user-message {
    background: linear-gradient(145deg, #2563eb 0%, #1e3a8a 100%);
    color: #e0e7ff;
    margin-left: auto;
    box-shadow: 0 8px 16px rgba(37, 99, 235, 0.3);
    border: 1px solid rgba(96, 165, 250, 0.5);
}

.assistant-message {
    background: linear-gradient(145deg, #1f2937 0%, #111827 100%);
    /* color: #d1d5db; */
    margin-right: auto;
    border: 1px solid #374151;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3),
        inset 0 0 12px rgba(59, 130, 246, 0.15);
}

.assistant-message::before {
    content: '';
    position: absolute;
    left: -18px;
    top: 14px;
    width: 12px;
    height: 12px;
    background: #3b82f6;
    border-radius: 50%;
    animation: neonPulse 1.2s infinite;
}

@keyframes messageSlide {
    from {
        transform: translateX(30px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes neonPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.6);
        transform: scale(0.95);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
        transform: scale(1.1);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
        transform: scale(0.95);
    }
}

.user-message {
    background: var(--primary-color);
    color: white;
    margin-left: auto;
    box-shadow: 0 3px 12px rgba(37, 99, 235, 0.15);
    border-bottom-right-radius: 0.5rem;
}

.assistant-message {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    margin-right: auto;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.05);
    border-bottom-left-radius: 0.5rem;
}

.assistant-message::before {
    content: '';
    position: absolute;
    left: -14px;
    top: 18px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #60a5fa;
    animation: pulse 1.2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.9);
        opacity: 0.8;
        box-shadow: 0 0 0 0 rgba(96, 165, 250, 0.4);
    }

    70% {
        transform: scale(1.1);
        box-shadow: 0 0 0 8px rgba(96, 165, 250, 0);
    }

    100% {
        transform: scale(0.9);
        opacity: 0.5;
    }
}

#input-box {
    display: flex;
    gap: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border-radius: 0.75rem;
    background: white;
}

#user-input {
    flex: 1;
    padding: 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 0.75rem;
    font-size: 1rem;
    transition: all 0.3s ease;
}

#user-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    transform: scale(1.02);
}

#save-btn {
    width: 60px;
    border: none;
    background: #3b82f6;
    color: white;
    padding: 0.8rem;
    border-radius: 0.5rem;
    position: fixed;
    right: 1rem;
    bottom: 10.5rem;
    cursor: pointer;
    /* transition: all 0.3s ease; */
}

#save-btn:hover {
    background: #2563eb;
    transform: scale(1.05);
}

#send-btn {
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#send-btn:hover {
    background: var(--secondary-color);
}

#send-btn.loading {
    opacity: 0.7;
    cursor: not-allowed;
}

.loading-dots {
    display: inline-block;
    position: relative;
    width: 1.5rem;
    height: 1rem;
}

.loading-dots div {
    position: absolute;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: currentColor;
    animation-timing-function: cubic-bezier(0, 1, 1, 0);
}

.loading-dots div:nth-child(1) {
    left: 0;
    animation: loading-dots1 0.6s infinite;
}

.loading-dots div:nth-child(2) {
    left: 0;
    animation: loading-dots2 0.6s infinite;
}

.loading-dots div:nth-child(3) {
    left: 1rem;
    animation: loading-dots2 0.6s infinite;
}

.loading-dots div:nth-child(4) {
    left: 2rem;
    animation: loading-dots3 0.6s infinite;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes loading-dots1 {
    0% {
        transform: scale(0);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes loading-dots3 {
    0% {
        transform: scale(1);
    }

    100% {
        transform: scale(0);
    }
}

@keyframes loading-dots2 {
    0% {
        transform: translate(0, 0);
    }

    100% {
        transform: translate(1rem, 0);
    }
}

#intro {
    color: white;
    /* padding: 1rem; */
    border-radius: 1rem;
    /* margin: 0.5rem 0; */
    transition: all 0.3s ease;
    cursor: pointer;
    overflow: hidden;
}

#intro:hover p {
    transform: translateY(0);
    opacity: 1;
}

#intro p {
    margin: 0;
    line-height: 1.4;
    font-size: 0.875rem;
    /* opacity: 0.9; */
    /* transform: translateY(10px); */
    /* opacity: 0; */
    /* transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); */
    transition-delay: 0.1s;
}

#intro h2 {
    margin: 0 0 0.5rem 0;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    /* 添加相对定位 */
    cursor: pointer;
    /* 添加手型指针 */
}

#intro p {
    position: absolute;
    left: 120%;
    top: 0;
    width: 200px;
    background: white;
    color: var(--text-color);
    padding: 1rem;
    border-radius: 0.75rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    opacity: 0;
    transform: translateX(-20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    z-index: 100;
}

#intro h2:hover+p {
    /* opacity: 1; */
    transform: translateX(0);
}

#intro p::before {
    content: '';
    /* position: absolute; */
    left: -8px;
    top: 12px;
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 8px solid white;
}

@media (max-width: 640px) {
    body {
        padding: 0.5rem;
    }

    .chat {
        height: calc(100vh - 150px);
    }
}

/* 顶部导航栏 */
#top-nav {
    background: var(--primary-color);
    color: white;
    padding: 0.8rem 2rem;
    display: flex;
    gap: 2rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
}

#top-nav div:nth-child(1) {
    display: flex;
    justify-content: space-evenly;
}

.nav-item {
    cursor: pointer;
    padding: 0.5rem 1rem;
    margin: 0 0.5rem;
    border-radius: 0.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(0);
    position: relative;

}

.nav-item.active::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 3px;
    background: white;
    border-radius: 2px;
    animation: navActive 0.3s ease-out;
}

@keyframes navActive {
    from {
        width: 20%;
        opacity: 0;
    }

    to {
        width: 60%;
        opacity: 1;
    }
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.nav-item.active {
    background: var(--secondary-color);
}

/* 主体容器 */
.main-container {
    display: flex;
    /* margin-top: 3.5rem; */
    /* 给顶部导航留出空间 */
    height: calc(100vh - 3.5rem);
}

/* 左侧历史记录栏 */
.history-sidebar {

    background: white;
    border-right: 1px solid #e2e8f0;
    padding: 1rem 0;
    /* 移除左右内边距 */
    margin-left: 0;
    /* 确保紧贴左侧 */
    overflow-y: auto;
}

/* 主体容器 */
.main-container {
    display: flex;
    /* margin-top: 3.5rem; */
    height: calc(100vh - 3.5rem);
    padding-left: 0;
    width: 100%;
    /* 新增宽度设置 */
}

.history-sidebar {
    margin-top: 3rem;
    width: 280px;
    /* 增加侧边栏宽度 */
    padding: 1rem;
    background: white;
    border-right: 1px solid #e2e8f0;
}

.chat-container {
    flex: 0.8;
    padding: 0 1rem;
    /* 调整内边距 */
    margin-left: 10px;
    /* 左移聊天区域 */
}

body {
    overflow: hidden;
    /* 禁用全局滚动 */
}

.main-container {
    overflow: hidden;
    /* 禁用容器滚动 */
}

.history-sidebar {
    overflow-y: auto;
    /* 保持侧边栏滚动 */
    height: calc(100vh - 3.5rem);
    /* 确保高度正确 */
}

.chat-container {
    overflow: hidden;
    /* 禁用右侧滚动 */
}

#chatbox {
    overflow-y: auto;
    /* 允许聊天框内部滚动 */
    height: calc(100vh - 160px);
    /* 动态高度计算 */
}

.history-item {
    padding: 1rem;
    margin: 0.5rem 0;
    background: rgba(37, 99, 235, 0.05);
    border-left: 3px solid var(--primary-color);
    transition: all 0.3s ease;
}

.history-item:hover {
    background: rgba(37, 99, 235, 0.1);
    transform: translateX(5px);
}

.history-time {
    font-size: 0.75rem;
    color: #64748b;
    margin-bottom: 4px;
}

.history-title {
    font-weight: 500;
    color: #1e293b;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-item {
    padding: 0.75rem;
    margin: 0.5rem 0;
    background: white;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.history-preview {
    font-size: 0.9em;
    color: #e2e8f0;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

#history-list {
    height: calc(100vh - 120px);
    /* 确保可视区域高度 */
    overflow-y: auto;
    /* 添加滚动条支持 */
    padding: 0.5rem;
}

/* 右侧聊天区域 */
.chat-container {
    /* opacity: 0; */
    transform: translateY(20px);
    animation: slideUp 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 调整原有chat样式 */
.chat {
    /* position: relative;
    left: -10px; */
    background: #f8fafc;
    border-radius: 1rem;

    z-index: 100;
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 90%;
}

#intro {
    position: relative;
    /* 添加相对定位 */
    overflow: visible;
    /* 允许内容溢出 */
}

#intro p {
    left: auto;
    right: calc(100% + 20px);
    /* 改为右侧定位 */
    top: 50%;
    transform: translateY(-50%);
    width: 240px;
    opacity: 0;
    transition: all 0.3s ease;
}

#intro p::before {
    left: auto;
    right: -8px;
    /* 调整箭头位置 */
    border-right: none;
    border-left: 8px solid white;
}


#intro h2:hover+p {
    opacity: 1;
}

#intro p::before {
    position: absolute;
    /* 取消注释 */
    right: 100%;
    left: auto;
    border-right-color: white;
    border-left: none;
}

#chatbox {
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

#chatbox::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari/Opera */
}

/* 
.history-sidebar {
    scrollbar-width: none;
    -ms-overflow-style: none;
} */

.history-sidebar::-webkit-scrollbar {
    display: none;
}

body::-webkit-scrollbar {
    display: none;
}

#chatbox {
    width: 95%;
    /* 从固定宽度改为百分比 */
    margin: 3rem auto;
    /* 增加左右外边距 */
    padding: 1.5rem 2rem;
    /* 增加水平内边距 */
}

.message {
    margin: 0.8rem 1.5rem;
    /* 增加左右边距 */
    max-width: 88%;
    /* 缩小最大宽度 */
}

@media (max-width: 640px) {
    #chatbox {
        width: 98%;
        padding: 1rem;
    }

    .message {
        margin: 0.8rem 0.5rem;
        max-width: 92%;
    }
}

.user-message {
    margin: 0.8rem 0;
    padding: 1rem 1.5rem;
    border-radius: 15px;
    max-width: 100%;
    /* 移除最大宽度限制 */
    min-width: 5px;
    /* 进一步缩小最小宽度 */
    width: max-content;
    /* 改用max-content实现精确内容适应 */
}

.user-message {
    margin-right: 2.5rem;
    /* 增加右侧间距 */
}

.assistant-message {
    margin-left: 2.5rem;
    /* 增加左侧间距 */
}

@media (max-width: 640px) {
    .message {
        min-width: 10px;
    }

    .user-message {
        margin-right: 1.2rem;
    }

    .assistant-message {
        margin-left: 1.2rem;
    }
}

.user-message {
    margin-left: auto;
    margin-right: 2rem;
    /* 用户消息右移 */
}

.assistant-message {
    margin-left: 2rem;
    /* 助理消息左移 */
    margin-right: auto;
}

@media (max-width: 640px) {
    .user-message {
        margin-right: 1rem;
    }

    .assistant-message {
        margin-left: 1rem;
    }
}

/* 新聊天按钮样式 */
.history-sidebar>div:first-child {
    background-color: #0d81f5;
    color: #E4E6EB;
    padding: 12px 20px;
    border-radius: 8px;
    margin: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    font-weight: 500;
}

.history-sidebar>div:first-child:hover {
    background-color: #235a91;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* 模态框样式 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(9, 8, 8, 0.5);
    z-index: 1000;
}

.modal-content {
    background-color: #fcfcfc;
    margin: 15% auto;
    padding: 20px;
    width: 400px;
    border-radius: 10px;
    position: relative;
}

.modal-header {
    border-bottom: 1px solid #3A3B3C;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.close-modal {
    float: right;
    cursor: pointer;
    font-size: 24px;
}

.setting-item {
    margin: 15px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* 优化后的设置弹窗样式 */
.modal-content {
    width: 30%;
    min-width: 350px;
    background: #b7babd;
    box-shadow: 0 8px 32px rgba(105, 104, 104, 0.3);
}

.setting-item {
    padding: 12px 16px;
    background: #ffffff;
    border-radius: 6px;
    margin: 12px 0;
    transition: all 0.2s ease;
}

.setting-item:hover {
    transform: translateX(5px);
    background: #ebebeb;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    color: #E4E6EB;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.close-btn:hover {
    transform: rotate(90deg);
}

.modal-content {
    background-color: #fcfcfc;
    margin: 15% auto;
    padding: 20px;
    width: 400px;
    border-radius: 10px;
    position: relative;
}

.modal-header {
    border-bottom: 1px solid #3A3B3C;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.close-modal {
    float: right;
    cursor: pointer;
    font-size: 24px;
}

.setting-item {
    margin: 15px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.close-btn {
    padding: 8px;
    font-size: 1.2rem;
    z-index: 1001;
    /* 确保按钮在最上层 */
}

.close-btn i {
    pointer-events: none;
    /* 避免图标干扰点击事件 */
}

/* 在.close-btn样式中添加 */
.close-btn:active {
    transform: scale(0.9);
    opacity: 0.8;
}

/* 游戏库样式 */
#game-library {
    display: none;
    padding: 20px;
    background: var(--primary-bg);
    border-radius: 12px;
    margin-top: 20px;
    position: absolute;
    right: 20px;
    top: 40px;
}

.game-item {
    padding: 12px 20px;
    margin: 10px 0;
    background: var(--secondary-bg);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.game-item:hover {
    transform: translateX(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* 修改游戏库定位方式 */
.game-library {
    position: absolute;
    top: 60px;
    right: 20px;
    left: 20px;
    bottom: 100px;
    display: none;
    background: var(--primary-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    z-index: 999;
}

/* 调整聊天容器高度 */
.chat-container {
    height: calc(100vh - 9px);
    /* transition: all 0.3s ease; */
}

@keyframes modalFadeOut {
    from {
        opacity: 1;
        transform: scale(1)
    }

    to {
        opacity: 0;
        transform: scale(0.9)
    }
}

.modal {
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9)
    }

    to {
        opacity: 1;
        transform: scale(1)
    }
}

.close-btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}